/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
 *
 * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
 * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
 *
 * Contributor(s): 
 *  Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
 *  
 * If you didn't download this code from the following link, you should check
 * if you aren't using an obsolete version: http://www.isqlviewer.com
 */
package org.isqlviewer.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.prefs.Preferences;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import org.isqlviewer.sql.ConnectionProfile;
import org.isqlviewer.swing.action.SwingEventManager;
import org.isqlviewer.util.LocalMessages;

/**
 * @author Mark A. Kobold &lt;mkobold at isqlviewer dot com&gt;
 * @version 1.0
 */
public class ConnectionProfileEditor extends AbstractApplicationView {

    private LocalMessages messages = new LocalMessages("org.isqlviewer.ui.ResourceBundle");
    private JComponent componentOwner = null;

    public void configureMenubar(JMenuBar menuBar) {

    }

    public void disposeView(Preferences preferences) {

        componentOwner.removeAll();
        componentOwner = null;
    }

    public void doLayout(JComponent parentComponent, Preferences preferences, SwingEventManager eventManager) {

        this.componentOwner = parentComponent;
        parentComponent.setLayout(new BoxLayout(parentComponent, BoxLayout.Y_AXIS));

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        GridBagConstraints constraint = null;
        String title = messages.format("connection_profile.jdbc_options");
        String tip = null;
        JLabel label = null;
        panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), title));

        title = messages.format("connection_profile.maximum_rows");
        tip = messages.format("connection_profile.maximum_rows.tip");
        JComponent component = new JSpinner();
        ((JSpinner) component).setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
        ((JSpinner) component).setEditor(new JSpinner.NumberEditor((JSpinner) component));
        component.setName(ConnectionProfile.JDBC_MAX_ROWS);
        component.setToolTipText(tip);
        constraint = constrain(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE);
        label = new JLabel(title);
        label.setLabelFor(component);
        panel.add(label, constraint);
        constraint = constrain(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
        panel.add(component, constraint);

        title = messages.format("connection_profile.maximum_field_size");
        tip = messages.format("connection_profile.maximum_field_size.tip");
        component = new JSpinner();
        ((JSpinner) component).setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
        ((JSpinner) component).setEditor(new JSpinner.NumberEditor((JSpinner) component));

        component.setName(ConnectionProfile.JDBC_MAX_FIELD_SIZE);
        component.setToolTipText(tip);
        constraint = constrain(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE);
        label = new JLabel(title);
        label.setLabelFor(component);
        panel.add(label, constraint);
        constraint = constrain(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
        panel.add(component, constraint);

        title = messages.format("connection_profile.is_escape_processing");
        tip = messages.format("connection_profile.is_escape_processing.tip");
        component = new JCheckBox(title);
        component.setName(ConnectionProfile.JDBC_ESCAPE_PROC);
        component.setToolTipText(tip);
        constraint = constrain(0, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
        panel.add(component, constraint);

        title = messages.format("connection_profile.tracing_enabled");
        tip = messages.format("connection_profile.tracing_enabled.tip");
        component = new JCheckBox(title);
        component.setName(ConnectionProfile.JDBC_TRACE_ENABLED);
        component.setToolTipText(tip);
        constraint = constrain(0, 3, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
        panel.add(component, constraint);

        title = messages.format("connection_profile.use_reverse_fetching");
        tip = messages.format("connection_profile.use_reverse_fetching.tip");
        component = new JCheckBox(title);
        component.setName(ConnectionProfile.JDBC_REVERSE_FETCHING);
        component.setToolTipText(tip);
        constraint = constrain(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
        panel.add(component, constraint);

        title = messages.format("connection_profile.generate_resultset_keys");
        tip = messages.format("connection_profile.generate_resultset_keys.tip");
        component = new JCheckBox(title);
        component.setName(ConnectionProfile.JDBC_GENERATE_KEYS);
        component.setToolTipText(tip);
        constraint = constrain(0, 5, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
        panel.add(component, constraint);

        component = (JComponent) Box.createVerticalGlue();
        component.setName("GLUE");
        component.setToolTipText(tip);
        constraint = constrain(0, 6, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL);
        panel.add(component, constraint);

        parentComponent.add(panel);
    }

    public void initializeView() {

    }

}
